//
//  AEHistoryPointsViewModel.m
//  AESOLAR_IOS
//
//  Created by Bin Tang on 2024/10/15.
//  Copyright © 2024 Mr.Wang. All rights reserved.
//

#import "AEHistoryPointsViewModel.h"
#import "AE_Solar-Swift.h"

@implementation AEHistoryPointsViewModel

- (void)initialize {
    [super initialize];
    
    self.title = [AEStringExten localizedValueWithKey:@"历史积分"];
    
    self.scoreNum = [AEAppDelegateTool sharedInstance].userInfoModel.scoreNum;
}

- (NSString *)getTypeName:(AEHistoryScoresModel *)model {
    model.isAdd = YES;
    if (model.type == 1) {
        return @"完善信息添加";
    } else if (model.type == 2) {
        return @"分享添加";
    } else if (model.type == 3) {
        return @"后台添加";
    } else if (model.type == 4) {
        return @"签到添加";
    } else if (model.type == 5) {
        return @"新闻添加";
    } else if (model.type == 6) {
        return @"评论添加";
    } else if (model.type == 7) {
        return @"浏览添加";
    } else if (model.type == 100) {
        model.isAdd = NO;
        return @"消费扣除";
    }
    return @"";
}

/// 获取历史积分
/// - Parameter completion: completion description
- (void)requestWithHistoryScores:(RequestCompletionBlock)completion {
    @weakify(self);
    AEHistoryScoresRequest *request = [[AEHistoryScoresRequest alloc] initWithPageNum:self.pageId pageSize:self.pageSize];
    [request startWithCompletionBlockWithSuccess:^(__kindof TYZBaseRequest * _Nonnull request) {
        @strongify(self);
        EDSRespondDataEntity *respond = request.responseModelObject;
        if (respond.code == EDS_NETWORK_SUCCESS) {
            if (self.pageId == 1) {
                [self.dataList removeAllObjects];
            }
            NSArray *list = respond.data;
            for (AEHistoryScoresModel *model in list) {
                model.scoreNum = [model.scoreNum stringByReplacingOccurrencesOfString:@"-" withString:@""];
                model.scoreNum = [model.scoreNum stringByReplacingOccurrencesOfString:@"+" withString:@""];
                model.typeName = [self getTypeName:model];
            }
            [self.dataList addObjectsFromArray:list];
            if (self.pageSize == list.count) {
                self.pageId += 1;
            }
        }
        [self sendResponseObject:request.responseModelObject completion:completion];
    } failure:^(__kindof TYZBaseRequest * _Nonnull request) {
        @strongify(self);
        [self sendResponseObject:request.responseModelObject completion:completion];
    }];
}

@end
